package com.jxaummd.mushroom.core.app.activity;

import android.app.Activity;
import android.content.Intent;
import android.text.TextUtils;


import com.jxaummd.mushroom.core.app.application.University;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class ActivityManager {
    //用来储存类
    public static final HashMap<String, Class> ACYICITYLIST = new HashMap<>();
    //用来储存对象
    public static List<Activity> ACTIVITIES =new ArrayList<>();

    public static void addObject(Activity activity) {
       ACTIVITIES.add(activity);
    }

    public static void removeObject(Activity activity) {
        ACTIVITIES.remove(activity);
    }

    public static void reLogin() {
        for (Activity activity :
                ACTIVITIES) {
            activity.finish();
        }
        University.getApplicationContext().startActivity(new Intent(University.getApplicationContext(),ACYICITYLIST.get("launch")));
    }



    public static void register(Class activity, String activityTag) {
        if (!TextUtils.isEmpty(activityTag) && activity != null) {
            ACYICITYLIST.put(activityTag, activity);
        }
    }



    public static Class getActivity(String tag) {
        Class activity = ACYICITYLIST.get(tag);
        if (tag != null) {
            return ACYICITYLIST.get(tag);
        }
        throw new NullPointerException("the tag can't map the activity");
    }



}
